package frobagroup.filter;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import javax.annotation.PostConstruct;
import javax.servlet.ServletException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * Created by Tinsley on 2016/11/22.
 */
@Component
public class WhiteList {
    @Value("${api.whitelist}")
    private String apiWhite;

    private List<String> whiteList = new ArrayList<String>(Arrays.asList(
            "/unAuth/"));


    @PostConstruct
    public void init() throws ServletException {
        try {
            if (!StringUtils.isEmpty(apiWhite)) {
                synchronized (whiteList) {
                    Collections.addAll(whiteList, apiWhite.split(","));
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public List<String> getWhiteList(){
        return this.whiteList;
    }
}
